package com.laboratory.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.laboratory.model.entity.Project;
import com.laboratory.model.dto.project.ProjectQueryDto;
import com.laboratory.service.ProjectService;
import com.laboratory.mapper.ProjectMapper;
import org.springframework.stereotype.Service;

/**
 *
 */
@Service
public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project>
    implements ProjectService{

    @Override
    public PageInfo<Project> getAll(Integer pIndex, Integer pSize, ProjectQueryDto projectQueryDto) {
        // 开启分页
        PageHelper.startPage(pIndex, pSize);

        // 条件
        QueryWrapper<Project> qw = new QueryWrapper<>();

        // 判断传过来的对象是否为空
        if (ObjectUtil.isNotEmpty(projectQueryDto)) {
            // 判断人项目类型是否为空
            if (StrUtil.isNotEmpty(projectQueryDto.getType())) {
                qw.eq("type", projectQueryDto.getType());
            }

            // 判断项目名称是否为空
            if (StrUtil.isNotEmpty(projectQueryDto.getName())) {
                qw.like("name", projectQueryDto.getName());
            }

            // 判断项目成员是否为空
            if (StrUtil.isNotEmpty(projectQueryDto.getMember())) {
                qw.like("member", projectQueryDto.getMember());
            }
        }

        //根据id倒序
        qw.orderByDesc("id");

        return new PageInfo<>(baseMapper.selectList((qw)));
    }
}




